<template>
  <div class='RemoveErrorBookDialog-container'>
    <view v-if="show" class="remove-alert-container">
      <view class="remove-content-bg">
        <text class="remove-title">确认移出错题？</text>
        <view style="margin-top: 72upx;display: flex;flex-direction: row">
          <view class="remove-btn" @click="show=false">取消</view>
          <view class="remove-btn primary" style="margin-left: 20upx" @click="remove">确定</view>
        </view>
      </view>
    </view>
  </div>
</template>

<script>
import {questionApi} from "@/api";
import questionCache from "@/libs/questionCache";

export default {
  name: 'RemoveErrorBookDialog',
  props: ['storeId'],
  data() {
    return {
      id: null,
      show: false
    }
  },
  mounted() {
    questionCache.getStore(this.storeId).subscribe('showRemoveErrorBookDialog', (res) => {
      this.id = res.id
      this.index = res.index
      this.show = true
    })
  },
  methods: {
    async remove() {
      questionCache.getStore(this.storeId).publish('removeQuestion', {index: this.index})
      this.show = false
      await questionApi.deleteWrong(this.id)
    }
  }
}
</script>

<style scoped lang='scss'>
.RemoveErrorBookDialog-container {
  .remove-alert-container {
    display: flex;
    flex-direction: column;
    background-color: rgba(0, 0, 0, 0.7);
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    justify-content: center;
    align-items: center;

    .remove-content-bg {
      display: flex;
      flex-direction: column;
      background-color: white;
      width: 558upx;
      height: 352upx;
      border-radius: 24upx;
      align-items: center;

      .remove-title {
        margin-top: 84upx;
        font-size: 36upx;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #000000;
        line-height: 50upx;
        align-self: center;
      }

      .remove-btn {
        display: flex;
        background-color: #F2F4F7;
        width: 232upx;
        height: 90upx;
        justify-content: center;
        align-items: center;
        font-size: 30upx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #474849;
        border-radius: 45upx;
        &.primary {
          background-color: #3073f6;
          color: #fff;
        }
      }
    }
  }
}
</style>
